package com.wanxi.user.controller;


import com.wanxi.common.entity.LoginParams;
import com.wanxi.common.entity.User;
import com.wanxi.common.result.CommonResult;
import com.wanxi.common.result.ResultDTO;
import com.wanxi.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class UserController {


    @Autowired
    UserService userService;

    /**
     * 远程权限验证
     * @param uri
     * @param username
     * @return
     */
    @GetMapping("/checkAccessToUri")
    public CommonResult checkAccessToUri(String uri, String username){
        return userService.checkAccessToUri(uri,username);
    }


    // 进行用户的认证，获取jwt token
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResultDTO login(LoginParams loginParams) {
        ResultDTO resultDTO = userService.login(loginParams);
        return resultDTO;

    }


    @RequestMapping("/back/admin/add")
    public ResultDTO add(User user) {
        ResultDTO resultDTO = userService.add(user);
        return resultDTO;
    }


    @RequestMapping("/back/admin/findAll")
    public CommonResult findAll(User user) {
        CommonResult commonResult = userService.findAll(user);
        return commonResult;
    }


    @RequestMapping("/back/admin/delete")
    public ResultDTO delete(User user) {
        ResultDTO resultDTO = userService.delete(user);
        return resultDTO;
    }


    @RequestMapping("/back/admin/findById")
    public ResultDTO findById(Integer id) {
        ResultDTO resultDTO = userService.findById(id);
        return resultDTO;
    }


    @RequestMapping("/back/admin/update")
    public CommonResult update(User user) {
        CommonResult commonResult = userService.update(user);
        return commonResult;
    }


    @RequestMapping("/back/admin/updatePassword")
    @ResponseBody
    public ResultDTO password(User user) {
        ResultDTO resultDTO = userService.updatePassword(user);
        return resultDTO;
    }

}




